package com.bpmn.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bpmn.system.domain.SysDict;
import com.bpmn.system.mapper.SysDictMapper;
import com.bpmn.system.service.ISysDictService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author rain
 */
@Service
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> implements ISysDictService {

    @Override
    public IPage<SysDict> selectDictPage(IPage<SysDict> page, SysDict dict) {
        LambdaQueryWrapper<SysDict> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.hasText(dict.getName()), SysDict::getName, dict.getName())
                .like(StringUtils.hasText(dict.getType()), SysDict::getType, dict.getType())
                .eq(dict.getStatus() != null, SysDict::getStatus, dict.getStatus())
                .orderByDesc(SysDict::getCreateTime);
        return page(page, wrapper);
    }

    @Override
    public boolean checkDictTypeUnique(String type) {
        return count(new LambdaQueryWrapper<SysDict>().eq(SysDict::getType, type)) == 0;
    }
}